<?php
namespace Application\Model\Dao;

use Zend\ServiceManager\AbstractFactoryInterface;

class DaoAbstractFactory implements AbstractFactoryInterface
{
    
	/* (non-PHPdoc)
     * @see \Zend\ServiceManager\AbstractFactoryInterface::canCreateServiceWithName()
     */
    public function canCreateServiceWithName(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator, $name, $requestedName)
    {
        return class_exists($this->getCamelCasedDaoName($requestedName));
    }

	/* (non-PHPdoc)
     * @see \Zend\ServiceManager\AbstractFactoryInterface::createServiceWithName()
     */
    public function createServiceWithName(\Zend\ServiceManager\ServiceLocatorInterface $serviceLocator, $name, $requestedName)
    {
        $requestedName = $this->getCamelCasedDaoName($requestedName);
        $dao = new  $requestedName();
        return $dao;
    }
    
    private function getCamelCasedDaoName($str){
        $str = ucwords($str);
        $str = 'Application\Model\Dao\\'.$str;
        return $str.'Dao';
    }
}

?>